<?php

/**
 * Profil form.
 *
 * @package    explications_informatiques
 * @subpackage form
 * @author     Guimezanes Cyrille
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ProfilForm extends BaseSfGuardUserProfileForm
{
  /**
   * @see SfGuardUserProfileForm
   */
    public function configure()
  {
	  unset($this["user_id"],$this["firstname"],$this["lastname"],$this["validate_at"],$this["validate"],$this["level"],$this["user_agent"],$this["created_at"],$this["updated_at"]);
  }
  public function setup()
  {
	$this->setWidgets(array(
	
	  'id'          => new sfWidgetFormInputHidden(),
      //'user_id'     => new sfWidgetFormDoctrineChoice(array('model' => $this->getRelatedModelName('User'), 'add_empty' => false)),
	  'photo' => new sfWidgetFormInputFileEditable(array(
					// Label qui sera affiché
					'label'        => "Photo utilisateur",
					// Lien de la photo à afficher
					'file_src'     => $this->getObject()->getPhotoFileSrc(),
					// à vrai
					'is_image'     => true,
					// on modifie que si l'image existe
					'edit_mode'    => !$this->isNew(),
					// active l'option de suppression
					'with_delete'  => true
					)),
      //'email_new'   => new sfWidgetFormInputText(),
      //'firstname'   => new sfWidgetFormInputText(),
      //'lastname'    => new sfWidgetFormInputText(),
      //'validate_at' => new sfWidgetFormDateTime(),
      //'validate'    => new sfWidgetFormInputText(),
      'website'     => new sfWidgetFormInputText(array(),array("size" => 50)),
      'signature'   => new sfWidgetFormTextarea(array(),array("rows" => 10,"cols" => 50)),
      //'level'       => new sfWidgetFormInputText(),
      //'user_agent'  => new sfWidgetFormInputText(),
      'allow_mp'    => new sfWidgetFormInputCheckbox(array(),array("value" => "1")),
      'allow_mail'  => new sfWidgetFormInputCheckbox(array(),array("value" => "1")),
      //'created_at'  => new sfWidgetFormDateTime(),
      //'updated_at'  => new sfWidgetFormDateTime(),
	  'skin' 		=> new sfWidgetFormDoctrineChoice(array( 'model' => $this->getRelatedModelName('SkinsOwned'), 'key_method' => 'getIdSkin', 'add_empty' => 'Bleu foncé', 'query' => $q = Doctrine_Query::create()->from('SkinsOwned')->where('id_client = ?', sfContext::getInstance()->getUser()->getGuardUser()->getId())))
	));
	$this->widgetSchema->setNameFormat('profile[%s]');
	
	$this->setValidators(array(
	  'id'          => new sfValidatorString(array('required' => false)),
	  'photo' => new sfValidatorFile(array(
					// Définit si le champs est obligatoire ou non
					'required'   => false,
					// Le chemin où la photo sera uploadé
					'path'       => $this->getObject()->getPhotoDirSrc(),
					'mime_types' => 'web_images',
				)),
	  
      //'user_id'     => new sfValidatorDoctrineChoice(array('model' => $this->getRelatedModelName('User'))),
      //'email_new'   => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      //'firstname'   => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      //'lastname'    => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      //'validate_at' => new sfValidatorDateTime(array('required' => false)),
      //'validate'    => new sfValidatorString(array('max_length' => 33, 'required' => false)),
      'website'     => new sfValidatorString(array('max_length' => 150, 'required' => false), array('invalid' => 'Longeur maximale de l\'URL atteinte')),
      'signature'   => new sfValidatorString(array('max_length' => 500, 'required' => false), array('invalid' => 'Longeur maximale de la signature atteinte')),
      //'level'       => new sfValidatorString(array('max_length' => 5)),
      //'user_agent'  => new sfValidatorString(array('max_length' => 150)),
      'allow_mp'    => new sfValidatorString(array('max_length' => 1, 'required' => false)),
      'allow_mail'  => new sfValidatorString(array('max_length' => 1, 'required' => false)),
      'created_at'  => new sfValidatorDateTime(),
	  'photo_delete' => new sfValidatorPass(),
	  'skin' => new sfValidatorString(array('required' => false)),
      //'updated_at'  => new sfValidatorDateTime(),
	)); 
	 $this->validatorSchema->setPostValidator(
      new sfValidatorAnd(array(
        new sfValidatorDoctrineUnique(array('model' => 'sfGuardUserProfile', 'column' => array('user_id'))),
        new sfValidatorDoctrineUnique(array('model' => 'sfGuardUserProfile', 'column' => array('email_new'))),
      ))
    );
	$this->widgetSchema->setLabels(array(
    
	  //'email_new'		   => "Votre email",
	  'signature'	  	   => "Votre signature",
	  'website'		       => "Votre site web",
	  'allow_mp'		   => "Autoriser les messages privés",
	  'allow_mail'		   => "Autoriser les emails",
	  'avatar'		   => "Choissisez votre avatar",
	  'photo_delete'		   => "Supprimer la photo actuelle",
	  'skin'		       => "Sélection du skin à appliquer",
    ));
	$this->widgetSchema->setHelps(array(

	  'signature'	  	   => "Vous pouvez utiliser le HTML. Attention tout signature trop imposante pourra être supprimée par un modérateur",
	  'website'		       => "Vous pouvez indiquer votre site web pour en faire la promotion",
	  'allow_mp'		   => "En cochant cette case les membres du site pourront vous envoyer des messages privés",
	  'allow_mail'		   => "En cochant cette case les membres du site pourront vous envoyer des emails",
	  'skin'		       => "Choissisez le skin que vous voulez!",
    ));	

    
  }
}
